<template>
  <div>
    <el-tree-select
        v-model="model"
        :data="catalogOptions"
        check-strictly
        node-key="id"
        :render-after-expand="false"
        style="width: 240px"
    />
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import http from "@/utils/request";

const model = defineModel()
const props = defineProps({
  apiPrefix: {
    type: String,
    default: 'queryCatalog'
  },
  fetch: {
    type: Boolean,
    default: true
  },
});


const catalogOptions = ref([]);

onMounted(async () => {

  let param={};
  if (props.fetch) {
    param.fetch = 1;
    param.depth = 1;
  }
  param.sortField="sortNum";
  param.sortMethod="asc";

  let res = await http.post(`/${props.apiPrefix}/list`, param);
  if (res.code === 200) {
    // 添加"全部"节点作为第一个节点
    catalogOptions.value = res.data;
  }
})

</script>


<style scoped>

</style>
